Scaling: Remove Instances
We'll cover the following
Removing the explicit instances#
Now that our new ASG instances are up and are serving requests through our load balancer, we can safely remove our explicit instances without causing any disruption. To do so, we just need to remove every reference to them from our main.yml script, and redeploy:
- The entire
Instanceresource. - The entire
Instance2resource. - The entire
Targetsproperty from theLoadBalancerTargetGroupresource. - The
Ec2TagFiltersproperty from theStagingDeploymentGroupresource. - The
InstanceEndpointandInstanceEndpoint2outputs.
Now, let’s redeploy our infrastructure by running deploy-infra.sh.
If we hit the load balancer endpoint now, we should see our traffic split between the two instances in our ASG. The other two instances have been terminated.
It’s time to checkpoint all our changes and push them to GitHub.
Note: All the code has been already added and we are pushing it on our repository as well.
/
- deploy-infra.sh
Adding capacity in a pinch is much easier now. From the Auto Scaling console (FIGURE 1), you can select your ASG (FIGURE 2) and edit the desired capacity setting (FIGURE 3). The number of EC2 instances will automatically reflect your desired capacity within a few seconds.
NOTE: All these figures are shown below.



In order to get a pictorial view of our developed cloudformation stack so far, below is the design view which shows the resources we created and their relationships.

In the next lesson, we will create separate environments for staging and production.
